package com.whh.dao.role;

import com.whh.util.BaseUtils;
import com.whh.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoleDaoImpl implements RoleDao{
    //查询角色列表
    @Override
    public List<Role> getRoleList(Connection connection) {
        PreparedStatement pstm=null;
        ResultSet rs=null;
        List<Role> roleList=new ArrayList<>();

        if (connection!=null){

            try {
                String sql="select*from smbms_role";
                Object[] params={};
                rs= BaseUtils.execute(connection,pstm,rs,sql,params);
                while (rs.next()){
                    Role role=new Role();
                    role.setId(rs.getInt("id"));
                    role.setRoleCode(rs.getString("roleCode"));
                    role.setRoleName(rs.getString("roleName"));
                    roleList.add(role);
                }
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }finally {
                BaseUtils.closeResource(null,pstm,rs);
            }
        }
        return roleList;
    }
}
